/*
 * Copyright (C) Michael Opitz
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA
 */
#ifndef UART_H
#define UART_H

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>

#include <stdio.h>
#include <stdint.h>
#define F_CPU 16000000 
#ifndef F_CPU
#define F_CPU 16000000             /* Oszillator-Frequency */
#endif
 
#define UART_UBRR_CALC(BAUD_,FREQ_) ((FREQ_)/((BAUD_)*16L)-1)
 
#define UART_BAUD_RATE 9600

/** 
 * \brief init_rs232 inits the rs232-connection
 */
void init_rs232();
/** 
 * \brief uart_flush flushes the rs232-connection
 */
void uart_flush();
/** 
 * \brief uart_getc_wait blocks until a char was received
 * 
 * \return the received char is returned.
 */
uint16_t uart_getc_wait();
/** 
 * \brief uart_getc returns a char received from the rs232-connection
 * 
 * \return -1 if nothing was received, the character if sth. was received
 */
uint16_t uart_getc();
/** 
 * \brief uart_puts sends a string over the rs232-connection
 * 
 * \param s is the string which should be sent
 */
void uart_puts (char *s);
/** 
 * \brief uart_putc sends a char over the rs232-connection
 * 
 * \param c is the char which should be sent
 * 
 * \return true if successful
 */
int uart_putc(unsigned char c);


#endif
